package com.xpgk.mvc.statistic.budgetYearStatistic;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.annotation.Service;
import com.xpgk.constant.ConstantRender;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.budgetYear.Budget;


@Service(name = BudgetYearStatisticService.serviceName)
public class BudgetYearStatisticService extends  BaseService{
	
	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(BudgetYearStatisticService.class);
	public static final String serviceName = "budgetYearStatisticService";
	/**获取需要审核的预算
	 * 列表
	 * @param startYear
	 * @param endYear
	 * @param organIds
	 * @return
	 */
	public  List<Record>  getAuditinfo(String startYear,String endYear,String organIds)
	{
			Map<String, Object> queryParam = new HashMap<String, Object>();
		    queryParam.put("startYear", startYear);
			queryParam.put("endYear", endYear);
			queryParam.put("parorganIds", organIds);
			queryParam.put("checkState", "2");
			List<Record> result=find(BudgetYearStatisticSQL.sqlId_getAuditInfo,queryParam);
			return  result;
	}
	/**获取预算列表
	 * 
	 * @param startYear
	 * @param endYear
	 * @param organIds
	 * @return
	 */
	public  List<Record>  getQueryinfo(String startYear,String endYear,String organIds)
	{
		Map<String, Object> queryParam = new HashMap<String, Object>();
	    queryParam.put("startYear", startYear);
		queryParam.put("endYear", endYear);
		queryParam.put("organIds", organIds);
		List<Record> result=find(BudgetYearStatisticSQL.sqlId_getAuditInfo,queryParam);
		return  result;
	}
	/**获取年度预算详情
	 * 
	 * @param ids
	 * @param organIds
	 * @param now
	 * @return
	 */
	public  List<Record> ShowBudgetYear(String ids,String organIds,String now)
	{	
		String oldyeartime=Integer.parseInt(now)-1+"-01-01 00:00:00";
		String nowyeartime=Integer.parseInt(now)+"-01-01 00:00:00";
		String nextyeartime=Integer.parseInt(now)+1+"-01-01 00:00:00";
		Map<String, Object> queryParam = new HashMap<String, Object>();
	    queryParam.put("oldyeartime", oldyeartime);
		queryParam.put("nowyeartime", nowyeartime);
		queryParam.put("nextyeartime", nextyeartime);
		queryParam.put("organIds", organIds);
		queryParam.put("nowyear", now);
		queryParam.put("budgetIds", ids);
		List<Record> result=find(BudgetYearStatisticSQL.sqlId_getBudgetYearInfo,queryParam);
		return  result;
	}
	
	
	/**更新审核状态
	 * 
	 * @param ids
	 * @param checkstate
	 * @param userIds
	 * @param checkreason
	 * @return
	 */
	public  String   passverification(String ids,String checkstate,String userIds,String checkreason)
	{	
		String msg=ConstantRender.render_success_code;
		Budget  budget=Budget.dao.findById(ids);
		if(budget!=null)
		{
			budget.set(Budget.column_check_state, checkstate)
					.set(Budget.column_check_time, new Date())
					.set(Budget.column_check_userID, userIds)
					.set(Budget.column_check_reason, checkreason)
					.set(Budget.column_gxsj,new Date());
			if(!budget.update())
			{
				log.debug("更新审核状态失败");
				throw new RuntimeException("更新审核状态失败!");
			}
		}
		return  msg;
	}
}
